<!-- 预警管理 -->
<template>
  <div>
    <ZgDialog v-model="visible" width="90%" :title="title">
      <Add ref="add" @ok="search"></Add>
      <Update ref="update" @ok="search"></Update>
      <ZgNewPage
        ref="page"
        :title="pageTitle"
        :showInlineBtn="false"
        :uniqueName="uniqueName"
        :pageOpt="pageOpt"
        :dataBtns="dataBtns"
        :extraBtns="extraBtns"
        :headers="headers"
        :conditions="conditions"
        :adminWidth="90"
        :scrollX="1500"
        @search="onSearch"
        @filter="onFilter"
        @header="mergeHeader"
        @admin="toAdmin"
        @extra="toExtra"
      >
        <template slot="columns">
          <a-table-column
            v-for="(h,i) in headers"
            :key="`column${i}`"
            :width="h.width===0 ? 'auto' : h.width"
            align="center"
            :title="h.label">
            <template slot-scope="record">
              <template>{{ record[h.code] }}</template>
            </template>
          </a-table-column>
        </template>
        <template slot="thMode" slot-scope="scope">
          <a-row :gutter="10">
            <a-col :span="4" v-for="t in scope.list" :key="`thMode_${t.id}`">
              <a-card class="mb10">
                <div class="wfull h100 scroll">
                  {{ t }}
                </div>
              </a-card>
            </a-col>
          </a-row>
        </template>
      </ZgNewPage>
    </ZgDialog>
  </div>
</template>
<script>
import Add from './Add'
import Update from './Update'
const list = [
    { value: '1', label: '1' },
    { value: '2', label: '2' },
    { value: '3', label: '3' }
]
export default {
  components: {
    Add, Update
  },
  data () {
    return {
      visible: false,
      title: '查看企业',
      pageTitle: '产品配置',
      uniqueName: 'test',
      pageOpt: {
        showConditionBtn: true,
        showHeaderConfig: true,
        showAttachBtn: true,
        showPageTitle: false
      },
      conditions: [
        { code: 'select', compType: '下拉选择', label: '预警场景', defaultVal: '', extra: { 下拉选项: list } },
        { code: 'select', compType: '下拉选择', label: '联系人', defaultVal: '', extra: { 下拉选项: list } },
        { code: 'select', compType: '下拉选择', label: '联系电话', defaultVal: '', extra: { 下拉选项: list } },
        { code: 'select', compType: '下拉选择', label: '企业名称', defaultVal: '', extra: { 下拉选项: list } },
        { code: 'creator', compType: '单行文本', label: '创建人', defaultVal: '' }
      ],
      headers: [
        { code: 'A', label: '企业名称', isShow: true, sort: 0 },
        { code: 'B', label: '企业类型', isShow: true, sort: 0 },
        { code: 'C', label: '企业等级', isShow: true, sort: 0 },
        { code: 'D', label: '联系人', isShow: true, sort: 0 },
        { code: 'E', label: '联系电话', isShow: true, sort: 0 },
        { code: 'F', label: '最近活动时间', isShow: true, sort: 0 },
        { code: 'G', label: '失活天数', isShow: true, sort: 0 },
        { code: 'H', label: '预警次数', isShow: true, sort: 0 },
        { code: 'I', label: '预警等级', isShow: true, sort: 0 }
      ],
      dataBtns: [
        { key: 1, name: '详情', type: 'link', isShow: () => { return true } }
      ],
      extraBtns: [
        { key: 1, name: '新增', icon: 'plus-circle', type: 'primary' }
      ]
    }
  },
  methods: {
    open () {
      this.visible = true
    },
    search () {
      this.$refs.page.search()
    },
    onSearch (param) {
      const diyHeaders = localStorage.getItem(this.currentUser.username + '_diyHeader_' + this.uniqueName)
      if (diyHeaders) {
        this.mergeHeader(JSON.parse(diyHeaders))
      }
      // 加载表头
      const list = [
        { key: '1', id: '1', A: '1111', B: '2222', C: 'A', D: '李华', E: '13333333333', F: '2025-6-11', G: '2025-6-11', H: '11', I: 'A' },
        { key: '2', id: '2', A: '1111', B: '2222', C: 'A', D: '李华', E: '13333333333', F: '2025-6-11', G: '2025-6-11', H: '4', I: 'B' }
      ]
      this.$refs.page.endSearch({
        total: list.length,
        list: list
      })
    },
    onFilter (f, param) {
    },
    toAdd () {
      alert('新增数据')
       //   this.$refs.add.open()
    },
    toAdmin (param) {
      if (param.key === 1) {
        this.$refs.update.open({}, 'details')
      } else if (param.key === 2) {
        this.$refs.update.open()
      } else if (param.key === 3) {
         this.confirm(
          () => {
            // this.$http.post('/zg-system/attach/del', [param.obj.id], () => {
            //   this.$refs.page.search()
            // })
          },
        '确定要删除这条数据么')
      } else if (param.key === 4) {
      }
    },
    toExtra (opt) {
      this.$refs.add.open()
    },
    mergeHeader (newHeaders) {
      if (!newHeaders) {
        return
      }
      this.headers = newHeaders.filter(t => {
        return t.isShow
      }).sort((a, b) => {
        return a.sort - b.sort
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
